package hypeerweb;

import java.io.Serializable;

/**
 * The Class DownPointingNodeState, a specific state for a node.<br/>
 * <br/>
 *
 * <b>Domain:</b>
 * 		STATE_ID	: int
 * 		singleton	: NodeState
 * 
 * <b>Invariants:</b>
 * 		singleton contains only representation of DownPointingNodeState in the program
 * 
 * @author Ryan Hess
 */
public class DownPointingNodeState extends NodeState implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -8959840811922684087L;

	/** The state id that each State returns.  2 for down pointing state. */
	public static final int STATE_ID = 2;
    
	/** The singleton representation for this state. */
    private static NodeState singleton;

    /**
     * Gets the singleton representation of the down pointing node state.
     * If no singleton has been created, creates one.
     *
     * @pre <i>None</i>
     * @post the singleton representation for the StandardNodeState
     */
    public static NodeState getSingleton() {
        if(singleton == null) {
            singleton = new DownPointingNodeState();
        }
        return singleton;
    }
    
     /**
     * Default constructor.  Private, only called by getSingleton().
     * 
     * @pre <i>None</i>
     * @post A new empty HypercubeCapState is created
     */
    private DownPointingNodeState() {}

    /* (non-Javadoc)
     * @see hypeerweb.NodeState#getCapNode(hypeerweb.Node)
     */
	@Override
    public Node getCapNode(Node self) {
    	return self.getLargestSurrogateNeighbor();
    }

    /* (non-Javadoc)
     * @see hypeerweb.NodeState#getInsertionNode(hypeerweb.Node)
     */
	@Override
    public Node getInsertionNode(Node self) {
        throw new UnsupportedOperationException("Why are you looking for the Insertion Node from a DownPointing node?  That doesn't make any sense!");
    }
    
    /* (non-Javadoc)
     * @see hypeerweb.NodeState#getID()
     */
    @SuppressWarnings("static-access")
	@Override
    public int getID() {
        return this.STATE_ID;
    }
    
    /* (non-Javadoc)
     * @see hypeerweb.NodeState#getChildNodeState(hypeerweb.Node)
     */
	@Override
    public NodeState getChildNodeState(Node self)
    {
        throw new UnsupportedOperationException("A downpointing node shouldn't have any children!");
    }

    @Override
    public NodeState getParentNodeState(Node self)
    {
    	return StandardNodeState.getSingleton();
    }
    
    /* (non-Javadoc)
     * @see hypeerweb.NodeState#toString()
     */
	@Override
    public String toString() {
        return "Down Pointing Node State = 2";
    }
}
